{include file='pub/header'/}
<title>限时抢购</title>
</head>
<body class="pos-r">
<div>
    <nav class="breadcrumb">{$breadNav}</nav>
    <div class="page-container">
        <div class="cl pd-5 bg-1 bk-gray mt-20">
            <a class="btn btn-success radius r" style="line-height:1.6em;margin-top:3px"
               href="javascript:location.replace(location.href);" title="刷新">
                <i class="Hui-iconfont">&#xe68f;</i>
            </a>
        </div>
        <div class="mt-20">
            <table class="table table-border table-bordered table-bg table-hover table-sort">
                <thead>
                <tr class="text-c">
                    <th width="40"><input name="" type="checkbox" value=""></th>
                    <th width="40">ID</th>
                    <th width="40">商品货号</th>
                    <th width="100">商品名称</th>
                    <th width="100">开始时间</th>
                    <th width="100">结束时间</th>
                    <th width="100">状态</th>
                    <th width="100">操作</th>
                </tr>
                </thead>
                <tbody>
                {foreach $list as $good}
                <tr class="text-c va-m">
                    <td><input name="id" type="checkbox" value="{$good.id}"></td>
                    <td>{$good.id}</td>
                    <td>{$good.gno}</td>
                    <td class="text-c">
                        {$good.name}
                    </td>
                    <td class="text-c">
                        {$good.start_time}
                    </td>
                    <td class="text-c">
                        {$good.end_time}
                    </td>
                    <td class="text-c">
                        <a class="btn btn-primary radius" href="javascript:;"
                           onclick="changeStatus('{$good.id}', '{$good.status}')">
                            {if $good.status eq 0}
                            开启
                            {else/}
                            关闭
                            {/if}
                        </a>

                    </td>
                    <td class="td-manage">
                        <a style="text-decoration:none" class="ml-5"
                           onClick="active_edit('活动编辑','{:url(\'Products/sec_active_edit\', [\'active_id\'=>$good.id])}')"
                           href="javascript:;" title="活动编辑">
                            <i class="Hui-iconfont">&#xe6df;</i>活动编辑
                        </a>
                        <a style="text-decoration:none" class="ml-5"
                           onClick="product_edit('商品编辑','{:url(\'Products/productEdit\', [\'good_id\'=>$good.good_id])}')"
                           href="javascript:;" title="商品编辑">
                            <i class="Hui-iconfont">&#xe6df;</i>商品编辑
                        </a>
                        <a style="text-decoration:none" class="ml-5" onClick="product_del(this,'{$good.id}')"
                           href="javascript:;" title="删除">
                            <i class="Hui-iconfont">&#xe6e2;</i>删除
                        </a>
                    </td>
                </tr>
                {/foreach}
                </tbody>
            </table>
        </div>
    </div>
</div>

{include file='pub/footer'/}
<script type="text/javascript">
    $('.table-sort').dataTable();

    function changeStatus(id, status){
        var tip = status==0?'开启':'关闭';
        layer.confirm('确认'+tip+'活动?',function () {
            $.post("{:url('Products/changeActive')}", {active_id:id, status:status}, function (res) {
                if(res.code == 1){
                    layer.msg('操作成功');
                    location.reload();
                }else if (res.code == 0) {
                    layer.alert('活动属性未设置，设置后操作', function () {
                        active_edit('活动编辑',"{:url('Products/sec_active_edit')}?active_id="+id);
                    });
                }else{
                    layer.msg('操作失败');
                }
            });
        });
    }

    /*产品-编辑*/
    function product_edit(title, url, id) {
        var index = layer.open({
            type: 2,
            title: title,
            content: url
        });
        layer.full(index);
    }

    /*产品-编辑*/
    function active_edit(title, url, id) {
        var index = layer.open({
            type: 2,
            title: title,
            content: url,
            area: ['500px','380px']
        });
    }

    /*产品-删除*/
    function product_del(obj, id) {
        layer.confirm('确认要删除吗？', function (index) {
            $.post("{:url('Products/delSecActive')}", {idstr: id}, function (res) {
                if (res.code == 1) {
                    layer.msg('删除成功');
                    $(obj).parents('tr').remove();
                } else {
                    layer.msg(res.msg);
                }
            });
        });
    }
</script>
</body>
</html>